package com.aoip.telemetry.telemetry.configureui.common.file.service.impl;

import com.aoip.telemetry.telemetry.configureui.common.file.mapper.FileBaseMapper;
import com.aoip.telemetry.telemetry.configureui.common.file.service.FileBaseService;
import com.aoip.telemetry.telemetry.configureui.common.utils.StringUtils;
import com.aoip.telemetry.telemetry.core.config.RuoYiConfig;
import com.aoip.telemetry.telemetry.entity.common.FileBaseEntity;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.io.File;
import java.util.List;

/**
 * @author chenbai
 * @version 1.0
 * @date 2022/2/16 15:48
 */
@Service
public class FileBaseServiceImpl implements FileBaseService {

    @Resource
    private FileBaseMapper mapper;

    @Override
    public List<FileBaseEntity> list(FileBaseEntity entity) {
        return null;
    }

    @Override
    public FileBaseEntity file(String id) {
        return mapper.selectById(id);
    }

    @Override
    public int insert(FileBaseEntity entity) {
        return mapper.insert(entity);
    }

    @Override
    public int update(FileBaseEntity entity) {
        return mapper.updateById(entity);
    }

    @Override
    public void delete(Long[] ids) {
        for (Long id : ids) {
            mapper.deleteById(id);
        }
    }

    @Override
    public String getFilePath(String fileId) {
        FileBaseEntity file = file(fileId);
        if (file == null) {
            return "";
        }
        String path = file.getFilePath();
        return path.replaceFirst("/profile", "");
    }

}
